﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TSSControlLibrary
{
    public partial class CronYearControl : UserControl
    {
        /// <summary>
        /// 回调函数  委托类型
        /// </summary>
        /// <param name="expression"></param>
        public delegate void Vaction(string expression, Control c);
        public Vaction returnExpression;
        /// <summary>
        /// 保存表达式信息
        /// </summary>
        private string ExPression = null;
        private bool endInitializeFlag;
        /// <summary>
        /// 控件构造函数
        /// </summary>
        public CronYearControl()
        {
            InitializeComponent();
            InitializeControl();
            endInitializeFlag = true;
        }
        /// <summary>
        /// 初始化控件数据
        /// </summary>
        private void InitializeControl()
        {           
            this.numericUpDown_wk1.Value = this.numericUpDown_wk1.Minimum;
            this.numericUpDown_wk2.Value = this.numericUpDown_wk2.Maximum;
            this.radioButton_bzd.Checked = true;
        }
        /// <summary>
        /// 选中按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton_bzd.Checked)
            {
                this.ExPression = "";
            }
            else if(radioButton_mn.Checked)
            {
                this.ExPression = "*";
            }
            else if(radioButton_wk.Checked)
            {
                this.ExPression = this.numericUpDown_wk1.Value + "-" + this.numericUpDown_wk2.Value;
            }
            //调用回调方法  返回表达式
            if (endInitializeFlag)
            {
                returnExpression(ExPression, this);
            }
        }
          /// <summary>
        /// 数字下拉框值改变时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void numericUpDown_ValueChanged(object sender, EventArgs e)
        {
            NumericUpDown n = sender as NumericUpDown;
            this.radioButton_wk.Checked = true;
            this.ExPression = this.numericUpDown_wk1.Value + "-" + this.numericUpDown_wk2.Value;
            //调用回调方法  返回表达式
            if (endInitializeFlag)
            {
                returnExpression(ExPression, this);
            }
        }
    }
}
